home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_9.zip / ADALIB2.C < prev    next >
C/C++ Source or Header  |  1993-07-27  |  14KB  |  391 lines

  1. /* liblist.c: translation of code generator read.stl*/
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "config.h"
  7. #include "segment.h"
  8. #include "slot.h"
  9. #include "ifile.h"
  10. #include "miscp.h"
  11. #include "libfp.h"
  12.  
  13. static void load_library();
  14. static void get_local_ref_maps(IFILE *, int);
  15. static long get_cde_slots(IFILE *, Axq);
  16. static void get_slot(IFILE *, char *);
  17. static char *convert_date(char *);
  18. static char *unit_name_name(char *);
  19. static int is_subunit(char *);
  20. static char *formatted_name(char *);
  21. static char *formatted_stub(char *);
  22.  
  23. IFILE *LIBFILE;
  24.  
  25. #ifdef IBM_PC
  26. /* on the PC, a chdir must be undone before program completes.
  27.  * changed_dir is set when directory changed.
  28.  */
  29. #endif
  30.  
  31.  
  32.  
  33.  
  34.  
  35. void main(int argc, char **argv)
  36. {
  37.         int  c;
  38.         int  lib_opt = FALSE;
  39.         int  errflg = 0;
  40.  
  41.         extern int  optind;
  42.         extern char *optarg;
  43.         char *libname,*fname;
  44.         char *t_name;
  45.  
  46. #ifdef IBM_PC
  47. /*      _outtext(" NYU Ada/Ed Librarian Version 1.11.1\n");
  48.         _outtext(" Copyright (C) 1985-1992 by New York University.");
  49. */
  50. #endif
  51.  
  52. #ifndef IBM_PC
  53.         while((c = getopt(argc,argv,"l:"))!=EOF) {
  54. #else
  55.         while((c = getopt(argc,argv,"L:l:"))!=EOF) {
  56.                 if (isupper(c)) c = tolower(c);
  57. #endif
  58.                 switch(c) {
  59.                 case 'l': /* specify library name */
  60.                         lib_opt = TRUE;
  61.                         libname = strjoin(optarg,"");
  62.                         break;
  63.                 case '?':
  64.                         errflg++;
  65.                 }        
  66.         }
  67.  
  68.         fname = (char *)0;
  69.         if (optind < argc) fname = argv[optind];
  70.         if (!lib_opt && fname == (char *)0) {
  71.                 fname = getenv("ADALIB");
  72.                 if (fname!= (char *)0) {
  73. #ifdef IBM_PC
  74.                         fprintf(stderr, "L");
  75. #else
  76.                         fprintf(stderr, "l");
  77. #endif
  78.                         fprintf(stderr,"ibrary defined by ADALIB: %s\n", fname);
  79.                 }
  80.         }
  81.         if ((!lib_opt && fname == (char *)0) || errflg) {
  82.             fprintf(stderr, "Usage: adalib [-l library]\n");
  83.             exit(1);
  84.         }
  85.         if (!lib_opt) {
  86.            libname = emalloc(strlen(fname) + 1);
  87.            strcpy(libname, fname);
  88.         }
  89.  
  90.         t_name = libset(libname);
  91.         LIBFILE = ifopen(LIBFILENAME, "", "r", 0);
  92.  
  93.         load_library();
  94.         exit(0);
  95. }
  96.  
  97. static void load_library()                                                              /*;load_library*/
  98. {
  99.         /*
  100.          * retrieve information from LIBFILE
  101.          * Called only if lib_option and not newlib.
  102.          */
  103.  
  104.         int             i, j, n, m, unumber, nodes, symbols;
  105.         int             comp_status, unit_count, cur_level;
  106.         char    *comp_date, *status_str, *uname, *aisname, *tmp_str;
  107.         char    *main_string, *fmt_name, *fmt_date;
  108.         int             is_main, empty_unit_slots, parent;
  109.         int             ignore;
  110.  
  111.         FILE *fout;
  112.         
  113.         fout = fopen("avllib.$$$","w");
  114.  
  115.         unit_count = getnum(LIBFILE,"lib-unit-count");
  116.         n = getnum(LIBFILE, "lib-n");
  117.         empty_unit_slots = getnum(LIBFILE, "lib-empty-slots");
  118.         tmp_str = getstr(LIBFILE,"lib-tmp-str");
  119.         for (i = 1; i <= unit_count; i++) {
  120.                 uname = getstr(LIBFILE, "lib-unit-name");
  121.                 unumber = getnum(LIBFILE, "lib-unit-number");
  122.                 aisname = getstr(LIBFILE, "lib-ais-name");
  123.                 comp_date = getstr(LIBFILE, "unit-date");
  124.                 symbols = getnum(LIBFILE, "lib-symbols");
  125.                 nodes = getnum(LIBFILE, "lib-nodes");
  126.                 is_main = getnum(LIBFILE, "lib-is-main");
  127.                 if (is_main) {
  128.                         if (streq(unit_name_type(uname), "ma")) {
  129.                                 main_string = "(Interface)";
  130.                                 }
  131.                         else  {
  132.                                 main_string = "  (Main)   ";
  133.                                 }
  134.                 }
  135.                 else {
  136.                         main_string = "";
  137.                 }
  138.                 comp_status = getnum(LIBFILE, "lib-status");
  139.                 status_str = (comp_status) ? "Active  " : "Obsolete";
  140.                 fmt_date = convert_date(comp_date);
  141.                 fmt_name = formatted_name(uname);
  142.  
  143.                 fprintf(fout,"%8s %11s %-15s %s\n",
  144.                     status_str, main_string, fmt_date, fmt_name);
  145.         }
  146.  
  147.         fprintf(fout,"\n");
  148.         n = getnum(LIBFILE, "lib-n");
  149.         if (n) {
  150. /*              fprintf(fout,"stubs \n\n"); */
  151.                 for (i = 1; i <= n; i++) {
  152.                         uname = getstr(LIBFILE, "lib-unit-name");
  153.                         aisname = getstr(LIBFILE, "lib-ais-name");
  154.                         parent = getnum(LIBFILE, "lib-parent");
  155.                         cur_level = getnum(LIBFILE, "lib-cur-level");
  156.                         m = getnum(LIBFILE, "stub-file-size");
  157.                         for (j = 1; j <= m; j++)
  158.                                 ignore = getnum(LIBFILE, "stub-file");
  159. /*                      fprintf(fout,"Stub               %s\n", formatted_stub(uname)); */
  160.                 }
  161. /*              fprintf(fout,"\n");  */
  162.         }
  163.  
  164.         fclose(fout);
  165.         ifclose(LIBFILE);
  166.  
  167.         return;
  168.  
  169. #ifdef TBSL
  170.         n = getnum(LIBFILE, "precedes-map-size");
  171.         printf("precedes map\n");
  172.         for (i = 1; i <= n; i += 2) {
  173.                 dom = getnum(LIBFILE, "precedes-map-dom");
  174.                 m = getnum(LIBFILE, "precedes-map-nelt");
  175.                 printf("  %4d:", dom);
  176.                 for (j = 1; j <= m; j++) {
  177.                         range = getnum(LIBFILE, "precedes-map-ent");
  178.                         printf(" %4d", range);
  179.                 }
  180.                 printf("\n");
  181.         }
  182.         n = getnum(LIBFILE, "compilation_table_size");
  183.         if (n) {
  184.                 printf("\ncompilation table\n");
  185.                 for (i = 1; i <= n; i++) {
  186.                         unum = (int) getnum(LIBFILE, "compilation-table-ent");
  187.                         printf("  %d\n", unum);
  188.                 }
  189.                 printf("\n");
  190.         }
  191.         /* late_instances */
  192.         n = getnum(LIBFILE, "late-instances-size");
  193.         if (n) {
  194.                 printf("late instances\n");
  195.                 for (i = 1; i <= n; i++) {
  196.                         str = (char *) getstr(LIBFILE, "late-instances-str");
  197.                         printf("  %s\n", str);
  198.                 }
  199.         }
  200.         /* current code segment */
  201.         n = getnum(LIBFILE, "unit-size");
  202.         printf("\ncurrent code segments\n");
  203.         printf("  unit cs\n");
  204.         for (i = 1; i <= n; i++) {
  205.                 cs = getnum(LIBFILE, "current-code-segment");
  206.                 if (cs) printf("   %d: %d\n", i, cs);
  207.         }
  208.         /* local reference maps */
  209.         n = getnum(LIBFILE, "unit-size");
  210.         get_local_ref_maps(LIBFILE, n);
  211.         cde_pos = get_cde_slots(LIBFILE, axq);
  212.  
  213.  
  214.         /* could free axq_data_slots, etc., but keep for now */
  215.         /* read out LIB_STUB map (always empty for now) */
  216.         ifclose(LIBFILE);
  217.         return;
  218. #endif
  219. }
  220.  
  221. static void get_local_ref_maps(IFILE *ifile, int units) /*;get_local_ref_map*/
  222. {
  223.         int             unit, defined, i, off, n;
  224.         int             sym_seq, sym_unit;
  225.  
  226.         printf("\nlocal reference maps\n");
  227.         for (unit = 1; unit <= units; unit++) {
  228.                 /* ignore empty ref maps (predef units) and obselete units */
  229.                 defined = getnum(ifile, "local-ref-map-defined");
  230.                 if (!defined) continue;
  231.                 printf("%d: ", unit);
  232.                 n = getnum(ifile, "local-ref-map-size");
  233.                 n = n/2;
  234.                 for (i = 1; i <= n; i++) {
  235.                         sym_seq = getnum(ifile, "local-ref-map-sym-seq");
  236.                         sym_unit = getnum(ifile, "local-ref-map-sym-unit");
  237.